import axios from 'axios'

const instance = axios.create({
    baseURL: "http://kumanxuan1.f3322.net:8881/cms"
})
// 请求拦截器
instance.interceptors.request.use(config => {
    console.log("请求拦截器");
    let token = localStorage.getItem("x-auth-token")
    if (token) {
        config.headers["x-auth-token"] = token
    }
    return config;
}, err => {
    return Promise.reject(err)
})

// 响应拦截器
instance.interceptors.response.use(function (response) {
    if (response.data.code != 0 && response.data.code != 400 && response.data.code != 407) {
        alert("【拦截器】", response.data.message);
        return
    }
    return response.data;
}, err => {
    return Promise.reject(err)
})

export default instance